/**
 * 
 */
package structures;
import java.util.List;
import java.util.Random;
import java.io.Serializable;

import Items.Item;
import structures.Status;
/**
 * Creates the individual passengers and handles their health statuses
 * @author Andrew Van Deventer
 *
 */
public class Passenger implements Serializable {
	private String name;
	private Status pStatus;
	private double health;
	//private static List<Passenger> crew;
	
	/**
	 * The constructor, just sets up the name and status variables.
	 * @param name	name of passenger
	 * @param pStatus	status of passenger
	 */
	public Passenger(String name, Status pStatus) {
		this.name = name;
		this.pStatus = pStatus;
		health = 20;
	}
	
	/**
	 * A setter for the passenger's name to be used when the player
	 * inputs it
	 * @param passengerName
	 */
	public void setName(String passengerName){
		name = passengerName;
	}
	
	/**
	 * Name Accessor
	 * @return name
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * Status Accessor
	 * @return pStatus the status of this Passenger
	 */
	public Status getStatus() {
		return pStatus;
	}

	/**
	 * A setter for the passenger's status to be used to set the 
	 * health of the player when random events occur
	 * @param createStatus
	 */
	public void setStatus(Status createStatus){
		pStatus = createStatus;
	}
	
	/**
	 * Passenger eats inputed amount of rations
	 * @param rations
	 */
	public void eat(double rations){
		health = health + rations;
	}
	
	/**
	 * Health Accessor of this Passenger
	 * @return health
	 */
	public double getHealth(){
		return health;
	}
	
	/**
	 * Health Mutator for this Passenger
	 * @param health the new health of this passenger
	 */
	public void setHealth(double health){
		this.health = health;
	}
	
	/**
	 * Update the status of this passenger, randomly sets status
	 * @return pStatus the status of this Passenger
	 */
	public Status updateStatus(){
		Random generator = new Random();
		if(health <= 5){
			int randNumber = generator.nextInt(101) + 1;
			for(Status s : Status.values()){
				if(s.baseChance <= randNumber && randNumber <= s.ceilingChance){
					if(pStatus == Status.HEALTHY && pStatus != s)
						pStatus = s;
				}
			}
		}
		
		if(health <= -10){
			pStatus = Status.DEAD;
			
		}
		return pStatus;
	}
}
